# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx906 -run-pass=prologepilog -verify-machineinstrs %s -o - | FileCheck -check-prefix=GCN %s

# VGPR spill code in the prolog sets the `IsKill` flag for the spilled register
# based on the entry block's livein info.

---
name:            vgpr_use_after_prolog_spill
tracksRegLiveness: true
machineFunctionInfo:
  scratchRSrcReg:  '$sgpr0_sgpr1_sgpr2_sgpr3'
  frameOffsetReg:  '$sgpr33'
  stackPtrOffsetReg: '$sgpr32'
body:             |
  bb.0:
    liveins: $sgpr42, $vgpr0, $sgpr30_sgpr31

    ; GCN-LABEL: name: vgpr_use_after_prolog_spill
    ; GCN: liveins: $sgpr42, $vgpr0, $sgpr30_sgpr31
    ; GCN-NEXT: {{  $}}
    ; GCN-NEXT: $sgpr4_sgpr5 = S_XOR_SAVEEXEC_B64 -1, implicit-def $exec, implicit-def dead $scc, implicit $exec
    ; GCN-NEXT: BUFFER_STORE_DWORD_OFFSET $vgpr0, $sgpr0_sgpr1_sgpr2_sgpr3, $sgpr32, 0, 0, 0, implicit $exec :: (store (s32) into %stack.0, addrspace 5)
    ; GCN-NEXT: $exec = S_MOV_B64 killed $sgpr4_sgpr5
    ; GCN-NEXT: $vgpr0 = V_ADD_U32_e32 8192, killed $vgpr0, implicit $exec
    ; GCN-NEXT: $vgpr0 = V_WRITELANE_B32 killed $sgpr42, 0, $vgpr0
    ; GCN-NEXT: S_NOP 0, implicit-def $vgpr0
    ; GCN-NEXT: $sgpr4_sgpr5 = S_XOR_SAVEEXEC_B64 -1, implicit-def $exec, implicit-def dead $scc, implicit $exec
    ; GCN-NEXT: $vgpr0 = BUFFER_LOAD_DWORD_OFFSET $sgpr0_sgpr1_sgpr2_sgpr3, $sgpr32, 0, 0, 0, implicit $exec :: (load (s32) from %stack.0, addrspace 5)
    ; GCN-NEXT: $exec = S_MOV_B64 killed $sgpr4_sgpr5
    ; GCN-NEXT: S_SETPC_B64_return $sgpr30_sgpr31
    $vgpr0 = V_ADD_U32_e32 8192, killed $vgpr0, implicit $exec
    $vgpr0 = V_WRITELANE_B32 killed $sgpr42, 0, $vgpr0
    S_NOP 0, implicit-def $vgpr0
    S_SETPC_B64_return $sgpr30_sgpr31
...

---
name:            livein_vgpr_def_after_prolog_spill
tracksRegLiveness: true
machineFunctionInfo:
  scratchRSrcReg:  '$sgpr0_sgpr1_sgpr2_sgpr3'
  frameOffsetReg:  '$sgpr33'
  stackPtrOffsetReg: '$sgpr32'
body:             |
  bb.0:
    liveins: $sgpr42, $vgpr0, $vgpr1, $sgpr30_sgpr31

    ; GCN-LABEL: name: livein_vgpr_def_after_prolog_spill
    ; GCN: liveins: $sgpr42, $vgpr0, $vgpr1, $sgpr30_sgpr31
    ; GCN-NEXT: {{  $}}
    ; GCN-NEXT: $sgpr4_sgpr5 = S_XOR_SAVEEXEC_B64 -1, implicit-def $exec, implicit-def dead $scc, implicit $exec
    ; GCN-NEXT: BUFFER_STORE_DWORD_OFFSET $vgpr0, $sgpr0_sgpr1_sgpr2_sgpr3, $sgpr32, 0, 0, 0, implicit $exec :: (store (s32) into %stack.0, addrspace 5)
    ; GCN-NEXT: $exec = S_MOV_B64 killed $sgpr4_sgpr5
    ; GCN-NEXT: $vgpr0 = V_ADD_U32_e32 8192, killed $vgpr1, implicit $exec
    ; GCN-NEXT: $vgpr0 = V_WRITELANE_B32 killed $sgpr42, 0, $vgpr0
    ; GCN-NEXT: S_NOP 0, implicit-def $vgpr0
    ; GCN-NEXT: $sgpr4_sgpr5 = S_XOR_SAVEEXEC_B64 -1, implicit-def $exec, implicit-def dead $scc, implicit $exec
    ; GCN-NEXT: $vgpr0 = BUFFER_LOAD_DWORD_OFFSET $sgpr0_sgpr1_sgpr2_sgpr3, $sgpr32, 0, 0, 0, implicit $exec :: (load (s32) from %stack.0, addrspace 5)
    ; GCN-NEXT: $exec = S_MOV_B64 killed $sgpr4_sgpr5
    ; GCN-NEXT: S_SETPC_B64_return $sgpr30_sgpr31
    $vgpr0 = V_ADD_U32_e32 8192, killed $vgpr1, implicit $exec
    $vgpr0 = V_WRITELANE_B32 killed $sgpr42, 0, $vgpr0
    S_NOP 0, implicit-def $vgpr0
    S_SETPC_B64_return $sgpr30_sgpr31
...

---
name:            livein_vgpr_not_referred_in_entry_bb
tracksRegLiveness: true
machineFunctionInfo:
  scratchRSrcReg:  '$sgpr0_sgpr1_sgpr2_sgpr3'
  frameOffsetReg:  '$sgpr33'
  stackPtrOffsetReg: '$sgpr32'
body:             |
  ; GCN-LABEL: name: livein_vgpr_not_referred_in_entry_bb
  ; GCN: bb.0:
  ; GCN-NEXT:   successors: %bb.1(0x80000000)
  ; GCN-NEXT:   liveins: $sgpr42, $vgpr0, $sgpr30_sgpr31
  ; GCN-NEXT: {{  $}}
  ; GCN-NEXT:   $sgpr4_sgpr5 = S_XOR_SAVEEXEC_B64 -1, implicit-def $exec, implicit-def dead $scc, implicit $exec
  ; GCN-NEXT:   BUFFER_STORE_DWORD_OFFSET $vgpr0, $sgpr0_sgpr1_sgpr2_sgpr3, $sgpr32, 0, 0, 0, implicit $exec :: (store (s32) into %stack.0, addrspace 5)
  ; GCN-NEXT:   $exec = S_MOV_B64 killed $sgpr4_sgpr5
  ; GCN-NEXT:   S_NOP 0
  ; GCN-NEXT:   S_BRANCH %bb.1
  ; GCN-NEXT: {{  $}}
  ; GCN-NEXT: bb.1:
  ; GCN-NEXT:   liveins: $sgpr42, $vgpr0, $sgpr30_sgpr31
  ; GCN-NEXT: {{  $}}
  ; GCN-NEXT:   $vgpr0 = V_WRITELANE_B32 killed $sgpr42, 0, $vgpr0
  ; GCN-NEXT:   S_NOP 0, implicit-def $vgpr0
  ; GCN-NEXT:   $sgpr4_sgpr5 = S_XOR_SAVEEXEC_B64 -1, implicit-def $exec, implicit-def dead $scc, implicit $exec
  ; GCN-NEXT:   $vgpr0 = BUFFER_LOAD_DWORD_OFFSET $sgpr0_sgpr1_sgpr2_sgpr3, $sgpr32, 0, 0, 0, implicit $exec :: (load (s32) from %stack.0, addrspace 5)
  ; GCN-NEXT:   $exec = S_MOV_B64 killed $sgpr4_sgpr5
  ; GCN-NEXT:   S_SETPC_B64_return $sgpr30_sgpr31
  bb.0:
    liveins: $sgpr42, $vgpr0, $sgpr30_sgpr31
    S_NOP 0
    S_BRANCH %bb.1
  bb.1:
    liveins: $sgpr42, $vgpr0, $sgpr30_sgpr31
    $vgpr0 = V_WRITELANE_B32 killed $sgpr42, 0, $vgpr0
    S_NOP 0, implicit-def $vgpr0
    S_SETPC_B64_return $sgpr30_sgpr31
...
